package com.dc.service.impl;

import com.dc.base.em.ErrorMessageEnum;
import com.dc.base.vo.BaseModel;
import com.dc.base.vo.BusinessException;
import com.dc.dao.LoginLogDao;
import com.dc.model.LoginLog;
import com.dc.service.LoginLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginLogServiceImpl  implements LoginLogService {
    @Autowired
    LoginLogDao loginLogDao;
    public BaseModel selectPageLoginLog(Integer curr_page, Integer page_size, BaseModel baseModel, String user_name,String user_account) throws Exception {
        // 启动分页
        PageHelper.startPage(curr_page,page_size);
        List<LoginLog> loginLogList=loginLogDao.selectPageLoginLog(user_name,user_account);
        PageInfo pageInfo =new PageInfo(loginLogList,5);
        baseModel.setResultCode(0);
        baseModel.setMessage("分页查询登录日志成功！");
        baseModel.setData(pageInfo);
        return baseModel;
    }

    public BaseModel addLoginLog(LoginLog loginLog, BaseModel baseModel) throws Exception {
        //调用新增用户的dao
        Integer result=loginLogDao.insertLoginLog(loginLog);
        if(result<1){
            throw new BusinessException(ErrorMessageEnum.ADD_USER_ERROR);
        }
        baseModel.setResultCode(0);
        baseModel.setMessage("新增登录日志成功！");
        return baseModel;
    }
}
